﻿using UnityEngine;

public class 触控开关 : MonoBehaviour
{
    public GameObject[] 触控实例组;
    public GameObject 开启触控按钮;
    public GameObject 关闭触控按钮;
    public bool 开关 = false;

    private string 开关键值对名 = "kaiguan";

    void Start()
    {
        int 读出值 = PlayerPrefs.GetInt(开关键值对名, 0);

        if(读出值 == 0)
        {
            开关 = false;
        }
        else
        {
            开关 = true;
        }

        执行开关操作();
    }

    private void 执行开关操作()
    {
        foreach (GameObject 触控实例 in 触控实例组)
        {
            触控实例.SetActive(开关);
        }

        开启触控按钮.SetActive(!开关);
        关闭触控按钮.SetActive(开关);
    }

    public void 开启触控()
    {
        开关 = true;
        PlayerPrefs.SetInt(开关键值对名, 1);
        执行开关操作();
    }

    public void 关闭触控()
    {
        开关 = false;
        PlayerPrefs.SetInt(开关键值对名, 0);
        执行开关操作();
    }
}
